using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Deepcode.Flux.Core.Systems.CMS;
using Deepcode.Flux.Core.Systems.CMS.TemplateGallery;
using Deepcode.Flux.Core.Systems.Workflow.Bases;

public partial class Private_CMS_main_actions_checkin_getNotes : Deepcode.Flux.Core.UI.CMS.CMSActionPane
{
	#region Page Load Event
	/// <summary>
	/// Page Load event
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!Page.IsPostBack)
		{
		}
	}
	#endregion
	#region Interactions
	/// <summary>
	/// Type selected, go forward to the actual editor form itself
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void btnNext_Click(object sender, EventArgs e)
	{
		if( ! Page.IsValid ) return;

		ContentManager cms = new ContentManager();
		ContentObject o = cms.AdxGetByID( this.ContentID );
		if( o == null ) GoBack();

		// Check this content in
		cms.CheckIn( o.PK_ID, CurrentUser.PK_ID, fNotes.Text );

		// Audit
		Deepcode.Flux.Core.Systems.Audit.Quick.QuickAudit.RaiseInformation(new Deepcode.Flux.Core.Systems.Audit.Quick.AuditUser(),
			"Flux",
			"Content Manager",
			"checked in {0}", o.NodeTitle);
		
		// If there are no workflow definitions, just publish it now
		Definition [] defs = new Definitions().GetDefinitionsByHandlerID("ContentManagement");
		if (defs.Length < 1)
		{
			cms.SubmitForApproval(o.PK_ID, -1, CurrentUser.PK_ID);

			// Audit
			Deepcode.Flux.Core.Systems.Audit.Quick.QuickAudit.RaiseInformation(new Deepcode.Flux.Core.Systems.Audit.Quick.AuditUser(),
				"Flux",
				"Content Manager",
				"auto submitted for approval {0}", o.NodeTitle);
		}

		// Return back to list
		GoBack( true );
	}
	/// <summary>
	/// Cancel clicked - go back to content view listing
	/// </summary>
	/// <param name="sender"></param>
	/// <param name="e"></param>
	protected void btnCancel_Click(object sender, EventArgs e)
	{
		GoBack();
	}
	#endregion
}
